$("#search_t").bind("click focus", function () {             
   var endtimeTf = $dp.$('search_d');             
   WdatePicker({                            
	   maxDate: '#F{$dp.$D(\'search_d\')}',      
	   dateFmt: "yyyy-MM-dd",              
	   onpicked: function () { endtimeTf.focus(); }          
		});         
   });          
$("#search_d").bind("click focus", function () {       
	WdatePicker({           
	   minDate: '#F{$dp.$D(\'search_t\')}', 
	   dateFmt: "yyyy-MM-dd"       
   });         
});
var Query = RichBase.extend({
	statics : {
		currentPage : 0,
		last : "",
		//oData : {},
		queryState : {
			loading : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">加载数据...</p><img src="images/other/loading_1.gif" alt="" /></li>',
			empty : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">没有数据...</p></li>',
			fail : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">请求失败...</p></li>',
			unlogin : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">登录过期，请重新登录...</p></li>',
			timeout : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">网络请求超时...</p></li>',
			serverError : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">请求出错...</p></li>'
		},
		isObjEmpty : function(obj){
			for(var i in obj){
				return false;
			}
			return true;
		}
	}, 
	EVENTS : {
		"click" : {
			"#pagenavW .pageBtn" : "onPrevNextClick"
		}
	},
	init : function(opt){
		this.prevBtn = $("#prevPageBtn");
		this.nextBtn = $("#nextPageBtn");
		
	},
	onPrevNextClick : function(that,e){//翻页
		var tarBtn = $(e.currentTarget);
	
	},
	page_ : function(pa){
		console.log("pa"+pa)
		$(".tcdPageCode").createPage({
			pageCount:pa,
			current:1,
			 backFn:function(p){
				console.log(p);
				qQuery.query({
					pid : 16506,
					sid : 0,
					last:p
				});
			 }
		});
	},
	query : function(opt){
		var that = this;
		var opt = opt || {};
		var pageSize = opt.pageSize || 20;
		var last = opt.last || "";
		var currentPage = opt.last || "0";
		var sid = opt.sid;
		var pid = opt.pid;
		var bt = opt.bt;
		var et = opt.et;
		var ttimeout = opt.ttimeout || 20 * 60 * 1000;
		var data = {
			pageSize : pageSize,
			currentPage : last,
			sid : sid,
			pid : pid,
			bt : bt,
			et : et,
			act:"lists"
		};
		//that.page_(pageSize);
		//console.log("ty"+" "+ty)
		var listUl = $("#mlistUl");
		var pagenavW = $("#pagenavW");
		var status = this.statics.queryState;
			PFT.Ajax({
				url : "adjusting_o.html",
				type : "GET",
				dataType : "json",
				ttimeout : ttimeout,
				data : data,
				loading : function(){
					listUl.html(status["loading"]);
					pagenavW.hide();
				},
				removeLoading : function(res){
					that.statics.last = "";
					that.statics.currentPage += 1;
					listUl.html("");
					pagenavW.show();
				},
				timeout : function(){ listUl.html(status["timeout"]);},
				serverError : function(){ listUl.html(status["serverError"]);} 
			},function(res){
				var lists = res.list;
					if(!that.statics.isObjEmpty(lists)){
						that.buildHtml(res);
					}else{
						listUl.html(status["empty"]);
						$("#pagenavW").hide();
					}
			})
	},
	buildHtml : function(res,t,qu){
		var that = this;
		var lists = res.list;
		var str = "";
		var last = res.last;
		var data = lists;
		var total = res.total;
		var totalPage = res.totalPage || "0";
		$(".search_titile").attr("time",totalPage)
		str +=   '<thead>';
		str +=   '	<tr>';
		str +=   '		<th class="align_left">日期</th>';
		str +=   '		<th class="admin">操作员</th>';
		str +=   '		<th class="setwidth">操作说明</th>';
		str +=   '		<th class="setwidth_a">交易金额（元）</th>';
		str +=   '		<th class="note">备注</th>';
		str +=   '	</tr>';
		str +=   '</thead>';
		for(var i in data){
			str +=   '<tbody>';
			str +=   '<tr>';
			str +=   '	<td class="align_left">2015-9-16 11:37</td>';
			str +=   '	<td class="admin">'+data[i]["dname"]+'</td>';
			str +=   '	<td class="setwidth">线下预存/还款</td>';
			str +=   '	<td class="setwidth_a color_b">+'+data[i]["account"]+'</td>';
			str +=   '	<td class="note">这是测试测试</td>';
			str +=   '</tr>';
			str +=   '</tbody>';
		}
		$("#mlistUl").html(str);
		 $('#mlistUl tbody:odd').css("backgroundColor","#FAFAFA");
		 $("html,body").animate({"scrollTop":0})
	}	
});
var qQuery = new Query({container:$(".tb_card")});
var Main = RichBase.extend({
	statics : {},
	EVENTS : {
		"click" : {
			//".page_sub" : "page_sub"
		}},
	init : function(opt){
		var that = this;
		this.container = opt.container;
		this.prevBtn = $("#prevPageBtn");
		this.nextBtn = $("#nextPageBtn");
		var pid = $(".pid").val()
		var sid = $(".sid").val()
		qQuery.query({
			 pid : 16506,
			 sid : 0
		});
	},

});
var search = RichBase.extend({
	statics : {},
	EVENTS : {
		"click" : {
			"#scope_btn" : "search_sub"
		}},
	init : function(opt){
		var that = this;
	},
	search_sub :function(){ 
		var bt = $("#search_t").val();
		var et = $("#search_d").val();
		if(!bt || !et){
			PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">时间设定有误</p>');
			return false
		}else{
			qQuery.query({
				pid : 16506,
				sid : 0,
				aid : 1,
				did : 2,
				bt : bt,
				et : et
			});
			//console.log(bt+et)
		}
	}

});
new Main({container:$(".credit_ti")});
new search({container:$(".credit_search")});




